Component({
  properties: {
    // yy-status-6 | yy-status-1 | yy-status-4 | yy-status-2 | yy-status-5 | yy-status-3 | message | back-icon | approving | approved | org-icon | evaluate-edit | yunyingshang | row-black-plus | select-icon | pay-success | pay-type1 | pay-type4 | pay-type2 | pay-type3 | selected-icon | coupon-use | my-report | more-row | filter | my-waitservice1 | my-waitover | my-over | point-start | point-end | tel | selectedIcon | address-edit | row-black | my-service | tocollect-icon | service-collect | home-row | searchIcon | my-message | my-clear | my-address | my-org | my-contact | my-line-row | my-waitpay | my-waitapply | my-waitreceive | my-line4 | my-all | my-line2 | my-waitservice | my-line1 | my-line3 | my-line5 | my-cancel
    name: {
      type: String,
    },
    // string | string[]
    color: {
      type: null,
      observer: function(color) {
        this.setData({
          colors: this.fixColor(),
          isStr: typeof color === 'string',
        });
      }
    },
    size: {
      type: Number,
      value: 18,
      observer: function(size) {
        this.setData({
          svgSize: size / 750 * wx.getSystemInfoSync().windowWidth,
        });
      },
    },
  },
  data: {
    colors: '',
    svgSize: 18 / 750 * wx.getSystemInfoSync().windowWidth,
    quot: '"',
    isStr: true,
  },
  methods: {
    fixColor: function() {
      var color = this.data.color;
      var hex2rgb = this.hex2rgb;

      if (typeof color === 'string') {
        return color.indexOf('#') === 0 ? hex2rgb(color) : color;
      }

      return color.map(function (item) {
        return item.indexOf('#') === 0 ? hex2rgb(item) : item;
      });
    },
    hex2rgb: function(hex) {
      var rgb = [];

      hex = hex.substr(1);

      if (hex.length === 3) {
        hex = hex.replace(/(.)/g, '$1$1');
      }

      hex.replace(/../g, function(color) {
        rgb.push(parseInt(color, 0x10));
        return color;
      });

      return 'rgb(' + rgb.join(',') + ')';
    }
  }
});
